Repository navigation
Guard shared_ so a logger may report while close() runs - #15
Merged
Merged
Conversation
close() swapped shared_ out with no lock while the logger, on the sending thread, could be reading it through report(). A mutex now guards shared_ alone: close() swaps under it and report() and isEnabled() work from a copy taken under it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
dmccoystephenson
force-pushed
the
feature/guard-shared-against-close
branch
from
October 22, 2026 12:48
ca8cd84 to
72edf56
Compare
Member
Author
|
Self-review rubric (anchored on CI run 39781398795 at head
Judgment notes:
Do-not-auto-merge check: the diff touches no curl argv, quoting, spawn, This review comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener). drafted by Claude on behalf of Daniel Stephenson |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TraceClient::shared_is now guarded by a mutex of its own (sharedMutex_).close()swaps it out under that lock;report()(viaenqueue) andisEnabled()work from a copy taken under it (current()). Previouslyclose()swappedshared_with no lock while aLoggeron the sending thread could be reading it throughreport()— the ThreadSanitizer data race described in report() from inside the Logger races with close() on TraceClient::shared_ #14.std::mutexrather thanstd::atomic_loadon theshared_ptr: the atomic free functions are deprecated in C++20 and would trip-Werroron the c++20 legs.close()has swapped the state out is dropped, as before. The lock is held only for the swap/copy, never whileclose()waits, so a logger callingreport()cannot deadlock againstclose(). Every new lock acquisition is inside atry, soreport,close,isEnabledand the destructor still never throw.aLoggerMayReportWhileCloseIsRunning(registered intests[]): the logger signals the main thread, which callsclose()while the logger sleeps and then callsreport(), so nothing orders the swap against the read. This is the unsynchronised schedule from report() from inside the Logger races with close() on TraceClient::shared_ #14; the comment inaLoggerMayItselfReportnow points at it.Closes #14
Deferred
TRACE_CLIENT_CURLignored on Windows whenSystem32\curl.exeexists) was not picked: it asks the owner to choose between honouring the override and documenting the current behaviour, and it touches thecurl.exelookup, which is part of the documented security boundary.Test plan
make test(g++, C++11,-Werror):54 tests, 0 failed checks(53 before)make test STD=c++17andSTD=c++2a(local g++ lacks-std=c++20):54 tests, 0 failed checkslinux-sanitizers (thread)green — the local toolchain has no TSan runtime, so this is the anchor for the race; a temporary CI revert of the header is used to show the new test fails under TSan without the fixThis PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).
🤖 Generated with Claude Code
drafted by Claude on behalf of Daniel Stephenson